<template>
  <div class="edit-container">
    <el-form v-loading="formLoading" ref="form" :model="form" :rules="rules" label-width="140px">
      <el-form-item label="签到积分" prop="signIntegral">
        <el-input type="number" placeholder="签到积分" v-model="form.signIntegral" class="col" maxlength="200"/>
      </el-form-item>
<!--      <el-form-item label="连续签到天数" prop="continueSignDay">-->
<!--        <el-input type="number" placeholder="连续签到天数" v-model="form.continueSignDay" class="col" maxlength="800"/>-->
<!--      </el-form-item>-->
      <el-form-item label="连续签到赠送积分" prop="continueSignIntegral">
        <el-input type="number" placeholder="连续签到赠送积分" v-model="form.continueSignIntegral" class="col" maxlength="800"/>
      </el-form-item>
<!--      <el-form-item label="注册奖励积分" prop="register">-->
<!--        <el-input type="number" placeholder="注册奖励积分" v-model="form.register" class="col" maxlength="800"/>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="状态" prop="status">-->
<!--        <el-switch v-model="form.status" :active-value="1" :inactive-value="0"></el-switch>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button v-loading="saveLoading" element-loading-background="rgba(0, 0, 0, 0.3)" type="primary" @click="handlerSubmit" v-has-permi="['admin:commodity:save']">保存</el-button>
        <el-button @click="close">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import {detail, save} from "@/api/integral";
import {getForm} from "@/utils/utils";

export default {
  props:{
    id:{
      default:null
    }
  },
  data(){
    return{
      form:{
        id:null,
        continueSignDay:'',
        continueSignIntegral:'',
        status:1,
        signIntegral:'',
        register:''
      },
      rules:{
        signIntegral: [{ required: true, message: '请填写签到积分', trigger: ['blur'] }],
        continueSignDay: [{ required: true, message: '请填写连续签到天数', trigger: ['blur'] }],
        continueSignIntegral: [{ required: true, message: '请填写连续签到赠送积分', trigger: ['blur'] }],
        register: [{ required: true, message: '请填写注册奖励积分', trigger: ['blur'] }],
      },
      roles:[],
      saveLoading:false,
      formLoading:false,
    }
  },
  mounted() {
    if(this.id){
      this.getDetail();
    }
  },
  methods:{
    getDetail(){
      this.formLoading=true
      detail(this.id).then(res=>{
        getForm(res,this.form);
      }).finally(()=>{
        this.formLoading=false;
      })
    },
    handlerSubmit(){
      if(this.saveLoading||this.formLoading){
        return;
      }
      this.$refs.form.validate(valid=>{
        if(!valid)return;
        this.saveLoading=true;
        save(this.form).then(()=>{
          this.$message.success('保存成功');
          this.close();
        }).finally(()=>{
          this.saveLoading=false
        })
      })
    },
    close(){
      this.$emit('hideEditDialog')
    }
  }
}
</script>
<style lang="scss" scoped>
.col{
  width: 360px;
}
.img{
  width: 120px;
  height: 120px;
  margin-right: 10px;
}
.imgList{
  display: flex;
  flex-wrap: wrap;
  .img{
    width: 120px;
    height: 120px;
    margin-right: 10px;
  }
}
</style>
